package com.hd.hdxgddcommon.utils;


import com.hd.hdxgddcommon.utils.oss.OSSConfig;
import com.hd.hdxgddcommon.utils.oss.OSSUtil;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.Base64;

/**
 * 上传图片到云服务器
 */
public class UploadToRemoteUtil {

    public static String upload(MultipartFile file, String directory) {
        String upload = OSSUtil.upload(file, directory);
        return OSSConfig.BASE_URL + upload;
    }

    public static String upload(File file, String directory) {
        return "";
    }

    public static void delete(String key) {

    }

    public static byte[] base64ToBytes(String base64) {
        //js上传base64 前缀 base64:,
        if (base64.indexOf(",") > 0) {
            base64 = base64.split(",")[1];

        }
        /**
         * 2.解码成字节数组
         */
        Base64.Decoder decoder = Base64.getDecoder();
        byte[] bytes = decoder.decode(base64);
        return bytes;
    }

    //压缩尺寸上传
    public static String thumbnailsUpload(int width, int height, MultipartFile file, String directory) {
//        String upload = OSSUtil.approvalFile(file, directory);
        String upload = OSSUtil.approvalFile(file);
        return OSSConfig.BASE_URL + upload;
    }
}
